from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-09 14:05:28.918114
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 09, May, 2021
Time: 14:05:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1014
Nobs: 286.000 HQIC: -48.7908
Log likelihood: 3480.68 FPE: 4.07639e-22
AIC: -49.2519 Det(Omega_mle): 2.99188e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.385360 0.115615 3.333 0.001
L1.Burgenland 0.072615 0.059031 1.230 0.219
L1.Kärnten -0.225182 0.052517 -4.288 0.000
L1.Niederösterreich 0.111681 0.126477 0.883 0.377
L1.Oberösterreich 0.218303 0.122585 1.781 0.075
L1.Salzburg 0.279208 0.067250 4.152 0.000
L1.Steiermark 0.107183 0.086080 1.245 0.213
L1.Tirol 0.123007 0.059540 2.066 0.039
L1.Vorarlberg -0.031681 0.054759 -0.579 0.563
L1.Wien -0.032859 0.109848 -0.299 0.765
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.417223 0.133196 3.132 0.002
L1.Burgenland 0.004241 0.068008 0.062 0.950
L1.Kärnten 0.328569 0.060504 5.431 0.000
L1.Niederösterreich 0.124482 0.145710 0.854 0.393
L1.Oberösterreich -0.070511 0.141226 -0.499 0.618
L1.Salzburg 0.230175 0.077477 2.971 0.003
L1.Steiermark 0.088110 0.099170 0.888 0.374
L1.Tirol 0.138011 0.068593 2.012 0.044
L1.Vorarlberg 0.152149 0.063086 2.412 0.016
L1.Wien -0.403815 0.126552 -3.191 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.256596 0.058726 4.369 0.000
L1.Burgenland 0.104850 0.029985 3.497 0.000
L1.Kärnten -0.013527 0.026676 -0.507 0.612
L1.Niederösterreich 0.092598 0.064244 1.441 0.149
L1.Oberösterreich 0.281078 0.062267 4.514 0.000
L1.Salzburg 0.020337 0.034160 0.595 0.552
L1.Steiermark -0.001178 0.043724 -0.027 0.979
L1.Tirol 0.066457 0.030243 2.197 0.028
L1.Vorarlberg 0.076577 0.027815 2.753 0.006
L1.Wien 0.118139 0.055797 2.117 0.034
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204041 0.056009 3.643 0.000
L1.Burgenland 0.028519 0.028597 0.997 0.319
L1.Kärnten 0.009229 0.025442 0.363 0.717
L1.Niederösterreich 0.057754 0.061271 0.943 0.346
L1.Oberösterreich 0.393401 0.059386 6.625 0.000
L1.Salzburg 0.082463 0.032579 2.531 0.011
L1.Steiermark 0.131147 0.041701 3.145 0.002
L1.Tirol 0.052054 0.028844 1.805 0.071
L1.Vorarlberg 0.081546 0.026528 3.074 0.002
L1.Wien -0.041062 0.053215 -0.772 0.440
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.433322 0.110225 3.931 0.000
L1.Burgenland 0.104390 0.056279 1.855 0.064
L1.Kärnten 0.010260 0.050069 0.205 0.838
L1.Niederösterreich 0.033537 0.120581 0.278 0.781
L1.Oberösterreich 0.117010 0.116870 1.001 0.317
L1.Salzburg 0.060752 0.064115 0.948 0.343
L1.Steiermark 0.064226 0.082067 0.783 0.434
L1.Tirol 0.199791 0.056764 3.520 0.000
L1.Vorarlberg 0.038387 0.052206 0.735 0.462
L1.Wien -0.056894 0.104727 -0.543 0.587
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217009 0.086360 2.513 0.012
L1.Burgenland -0.012116 0.044094 -0.275 0.783
L1.Kärnten -0.006215 0.039229 -0.158 0.874
L1.Niederösterreich -0.015114 0.094474 -0.160 0.873
L1.Oberösterreich 0.415907 0.091567 4.542 0.000
L1.Salzburg 0.012159 0.050234 0.242 0.809
L1.Steiermark -0.028031 0.064299 -0.436 0.663
L1.Tirol 0.162019 0.044474 3.643 0.000
L1.Vorarlberg 0.058013 0.040903 1.418 0.156
L1.Wien 0.202303 0.082053 2.466 0.014
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177850 0.106336 1.673 0.094
L1.Burgenland 0.024561 0.054293 0.452 0.651
L1.Kärnten -0.071241 0.048302 -1.475 0.140
L1.Niederösterreich -0.035289 0.116326 -0.303 0.762
L1.Oberösterreich 0.013375 0.112746 0.119 0.906
L1.Salzburg 0.091214 0.061853 1.475 0.140
L1.Steiermark 0.315436 0.079172 3.984 0.000
L1.Tirol 0.460582 0.054761 8.411 0.000
L1.Vorarlberg 0.148093 0.050364 2.940 0.003
L1.Wien -0.123243 0.101031 -1.220 0.223
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206591 0.125241 1.650 0.099
L1.Burgenland 0.040021 0.063946 0.626 0.531
L1.Kärnten -0.074591 0.056890 -1.311 0.190
L1.Niederösterreich 0.117281 0.137008 0.856 0.392
L1.Oberösterreich 0.012602 0.132792 0.095 0.924
L1.Salzburg 0.194206 0.072850 2.666 0.008
L1.Steiermark 0.129971 0.093247 1.394 0.163
L1.Tirol 0.055455 0.064497 0.860 0.390
L1.Vorarlberg 0.106562 0.059318 1.796 0.072
L1.Wien 0.219863 0.118994 1.848 0.065
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.498063 0.069807 7.135 0.000
L1.Burgenland -0.012791 0.035642 -0.359 0.720
L1.Kärnten -0.017347 0.031710 -0.547 0.584
L1.Niederösterreich 0.111186 0.076366 1.456 0.145
L1.Oberösterreich 0.302710 0.074016 4.090 0.000
L1.Salzburg 0.023862 0.040605 0.588 0.557
L1.Steiermark -0.047163 0.051975 -0.907 0.364
L1.Tirol 0.081988 0.035949 2.281 0.023
L1.Vorarlberg 0.103748 0.033063 3.138 0.002
L1.Wien -0.041772 0.066325 -0.630 0.529
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.163037 0.090437 0.170756 0.222476 0.077362 0.094810 0.001188 0.165844
Kärnten 0.163037 1.000000 0.054392 0.213219 0.186725 -0.066907 0.179454 0.021231 0.308308
Niederösterreich 0.090437 0.054392 1.000000 0.241445 0.097174 0.316833 0.143189 0.024694 0.318498
Oberösterreich 0.170756 0.213219 0.241445 1.000000 0.300985 0.260344 0.105236 0.061569 0.143916
Salzburg 0.222476 0.186725 0.097174 0.300985 1.000000 0.148921 0.077756 0.090696 0.030346
Steiermark 0.077362 -0.066907 0.316833 0.260344 0.148921 1.000000 0.093140 0.100655 -0.100164
Tirol 0.094810 0.179454 0.143189 0.105236 0.077756 0.093140 1.000000 0.151816 0.160632
Vorarlberg 0.001188 0.021231 0.024694 0.061569 0.090696 0.100655 0.151816 1.000000 -0.009871
Wien 0.165844 0.308308 0.318498 0.143916 0.030346 -0.100164 0.160632 -0.009871 1.000000